home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Dialectic 1.2 / source / Dialectic ƒ / Shell ƒ / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.7 KB  |  118 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. \**********************************************************************/
  8.  
  9. #include "graphics.h"        /* needs to come first because it defines WindowDataHandle */
  10. #include "about.h"
  11. #include "prefs.h"
  12.  
  13. /*-----------------------------------------------------------------------------------*/
  14. /* internal stuff for about.c                                                        */
  15.  
  16. void SetupTheAboutBox(WindowDataHandle theData);
  17. void DrawTheAboutBox(Boolean isColor);
  18. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  19. void DrawTheAboutString(Str255 theString, int theWidth, int *theRow);
  20.  
  21.  
  22. int AboutBoxDispatch(ExtendedWindowDataHandle theData, int theMessage, unsigned long misc)
  23. {
  24.     int                theDepth;
  25.     
  26.     switch (theMessage)    /* see graphics.h for list of messages*/
  27.     {
  28.         case kKeydown:                            /* close about box on keypress */
  29.         case kMousedown:                        /* or mouseclick */
  30.             CloseTheWindow(theData);
  31.             return kSuccess;
  32.             break;
  33.         case kUpdate:
  34.             theDepth=misc&0x7fff;                /* pixel depth */
  35.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  36.             return kSuccess;
  37.             break;
  38.         case kStartup:
  39.             SetupTheAboutBox(theData);
  40.             return kSuccess;
  41.             break;
  42.     }
  43.     
  44.     return kFailure;        /* for all other messages, defer to default processing */
  45. }
  46.  
  47. void SetupTheAboutBox(WindowDataHandle theData)
  48. {
  49.     (**theData).windowWidth=184;
  50.     (**theData).windowHeight=216;
  51.     (**theData).windowType=altDBoxProc;        /* shadowed window */
  52.     (**theData).windowTitle[0]=0x00;        /* null title, never shown */
  53.     (**theData).hasCloseBox=FALSE;
  54. }
  55.  
  56. void DrawTheAboutBox(Boolean isColor)
  57. {
  58.     int                row;
  59.     Handle            textHandle;
  60.     Str255            theLine;
  61.     unsigned long    pos;
  62.     unsigned long    theSize;
  63.     GrafPtr            curPort;
  64.     int                theWidth;
  65.     
  66.     GetPort(&curPort);
  67.     EraseRect(&(curPort->portRect));
  68.     theWidth=(curPort->portRect.right)-(curPort->portRect.left);    /* for centering */
  69.     
  70.     TextFont(geneva);
  71.     TextSize(9);
  72.     TextMode(srcCopy);    /* straight copy, no bit-biddling */
  73.     if (isColor)
  74.         ForeColor(blueColor);
  75.     row=16;
  76.     textHandle=GetResource('TEXT', 128);    /* in .rsrc file */
  77.     if (textHandle==0L)                        /* if not there, don't draw anything (duh) */
  78.         return;
  79.     if (*textHandle==0L)                    /* there, but SetResLoad is false */
  80.         LoadResource(textHandle);            /* so get it already! */
  81.     if (*textHandle==0L)                    /* if empty, don't draw anything */
  82.         return;
  83.     pos=0L;
  84.     theSize=SizeResource(textHandle);        /* size in bytes of text */
  85.     do
  86.     {
  87.         GetTheNextLine(textHandle, theSize, &pos, theLine);    /* gets one line at a time */
  88.         DrawTheAboutString(theLine, theWidth, &row);        /* draw one line */
  89.     }                                                        /* (Quickdraw doesn't do <CR>) */
  90.     while (pos<theSize);
  91.     ReleaseResource(textHandle);    /* important!  otherwise we'll get memory leaks */
  92.     DrawTheAboutString("\pThis copy is registered to", theWidth, &row);
  93.     if (isColor)
  94.         ForeColor(redColor);
  95.     DrawTheAboutString(gMyName, theWidth, &row);
  96.     DrawTheAboutString(gMyOrg, theWidth, &row);
  97.     if (isColor)
  98.         ForeColor(blackColor);
  99. }
  100.  
  101. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  102. {
  103.     unsigned char    theChar;
  104.     
  105.     theLine[0]=0x00;
  106.     /* the beauty of C -- this just gathers characters in theLine (pascal string) until
  107.        (1) the end of the text, or (2) a return character */
  108.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  109.         theLine[++theLine[0]]=theChar;
  110. }
  111.  
  112. void DrawTheAboutString(Str255 theString, int theWidth, int *theRow)
  113. {
  114.     MoveTo((theWidth-StringWidth(theString))/2, *theRow);    /* center text in window */
  115.     DrawString(theString);
  116.     *theRow+=12;    /* Quickdraw doesn't advance row position for us */
  117. }
  118.